package dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import domain.Movies;

public class MovieInfoDaoHibernate extends HibernateDaoSupport implements
		MovieInfoDao {

	private static final String BASE_CONTACTS_QUERY = "from "
			+ Movies.class.getName() + " c ";

	public MovieInfoDaoHibernate() {
	}

	public Integer getId() {
		return (Integer) getHibernateTemplate().find(
				"select max(id) from Movies g").get(0);
	}

	public Movies getMovie(Integer id) {
		return (Movies) getHibernateTemplate().get(Movies.class, id);
	}

	@Override
	public void addMovie(Movies movie) {
		// TODO Auto-generated method stub
		getHibernateTemplate().saveOrUpdate(movie);
	}

	@Override
	public void deleteMovie(Movies movie) {
		// TODO Auto-generated method stub
		getHibernateTemplate().delete(movie);
	}

	@Override
	public List getMovies() {
		return getHibernateTemplate().find(BASE_CONTACTS_QUERY);
	}

}
